package com.edu.whty.entity.base;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 请求分页参数
 * 
 * @author shijiapeng
 * @date 2015年7月14日 下午3:31:51
 */
public class PageInfo {

	private Integer currPage = 1;// 请求页数
	private Integer pageSize = 10;// 页大小
	private Integer recordCount;// 记录数
	private Integer totalPage;//总页数
	
	public PageInfo(){};
	
	public PageInfo(int currPage, int pageSize) {
		this.currPage = currPage;
		this.pageSize = pageSize;
	}
	
	public PageInfo(int recordCount, int currentPage, int pageSize) {
		this.recordCount = recordCount;
		this.pageSize = pageSize;
		this.currPage = currentPage;
	}

	/**
	 * 数据库查询开始记录数
	 * @return
	 */
	@JSONField(serialize = false)
	public Integer getStart() {
		return (currPage - 1) * pageSize;
	}
	
	/**
	 * 数据库查询结束记录数
	 * @return
	 */
	@JSONField(serialize = false)
	public Integer getEnd() {
		return currPage * pageSize;
	}
	
	public Integer getCurrPage() {
		return currPage;
	}

	public void setCurrPage(Integer currPage) {
		this.currPage = currPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(Integer recordCount) {
		this.recordCount = recordCount;
	}

	public Integer getTotalPage() {
		if (totalPage != null && totalPage>0) {
			return totalPage;
		} else {
			recordCount = recordCount==null?0:recordCount;
			int totalP = recordCount/pageSize;
			if (recordCount%pageSize == 0) {
				return totalP;
			} else {
				return totalP + 1;
			}
		}
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	@Override
	public String toString() {
		return "PageInfo [currPage=" + currPage + ", pageSize=" + pageSize
				+ ", recordCount=" + recordCount + ", totalPage=" + totalPage
				+ "]";
	}

}
